home *** CD-ROM | disk | FTP | other *** search
Oberon Text | 1995-12-04 | 17.1 KB | 324 lines | [TEXT/.Ob4] |
- Syntax10.Scn.Fnt
- BalloonElems
- Alloc
- Syntax10.Scn.Fnt
- "VersionElems"
- Version elements simplify the handling of multiple
- versions of a module in the same source file.
- Text pieces that differ from one version to the
- other are enclosed in version elements which look
- like angle brackets. When the user middle-clicks
- on the opening bracket a popup menu with a list
- of version names appears. Selecting one of the
- names replaces the bracketed text with the text
- that is stored for the selected version.
- "Beg"
- The opening bracket of a pair of version elements.
- When it is clicked at it shows a list of version names.
- Selecting one of these names replaces the text
- between the Beg and the End element with the
- text that is stored for this version name.
- "End"
- The closing bracket of a pair of version elements.
- "CheckMenu"
- Makes sure that the variants in the element
- are exactly the variants in the popup menu.
- "IndexOf"
- e.IndexOf(vers) returns the index i so that
- e.buf[i] is the text corresponding to vers.
- "TwinPos"
- e.TwinPos() returns the position of the
- corresponding right bracket of e.
- "SwitchTo"
- e.SwitchTo(vers) switches the element e to
- version vers.
- "Insert"
- VersionElems.Insert name
- Inserts a pair of version elements around the
- current selection. 'name' is the version name.
- "SetVersion"
- VersionElems.SetVersion name
- Switches all version elements in the marked text
- to version 'name'.
- "Find"
- VersionElems.Find
- Searches the next version element starting from the
- caret position and sets the caret to this element.
- StampElems
- Alloc
- 4 Dec 95
- Syntax10b.Scn.Fnt
- Syntax10i.Scn.Fnt
- FoldElems
- Syntax10.Scn.Fnt
- VAR i: INTEGER;
- BEGIN
- i := 0;
- WHILE (i < maxVersions) & (e.vers[i] # "") DO
- IF e.vers[i] = version THEN RETURN i END;
- INC(i)
- END;
- RETURN -1
- END IndexOf;
- Syntax10.Scn.Fnt
- VAR s: Texts.Scanner; vers: ARRAY maxVersions, 32 OF CHAR; buf: ARRAY maxVersions OF Texts.Buffer; i, j: INTEGER;
- BEGIN
- Texts.OpenScanner(s, e.menu, 0); i := 0;
- REPEAT
- Texts.Scan(s);
- IF (i < maxVersions) & (s.class = Texts.Name) THEN
- COPY(s.s, vers[i]);
- j := e.IndexOf(s.s);
- IF j >= 0 THEN buf[i] := e.buf[j] ELSE NEW(buf[i]); Texts.OpenBuf(buf[i]) END;
- INC(i)
- END
- UNTIL s.eot;
- FOR j := 0 TO i-1 DO COPY(vers[j], e.vers[j]); e.buf[j] := buf[j] END;
- IF i < maxVersions THEN e.vers[i] := "" END
- END CheckMenu;
- Syntax10.Scn.Fnt
- VAR r: Texts.Reader; level: INTEGER;
- BEGIN
- Texts.OpenReader(r, Texts.ElemBase(e), Texts.ElemPos(e)+1);
- level := 1;
- LOOP
- Texts.ReadElem(r);
- IF r.eot THEN RETURN -1
- ELSIF r.elem IS Beg THEN INC(level)
- ELSIF r.elem IS End THEN DEC(level);
- IF level = 0 THEN RETURN Texts.Pos(r) - 1 END
- END
- END TwinPos;
- Syntax10.Scn.Fnt
- VAR t: Texts.Text; beg, end: LONGINT; i, j: INTEGER;
- BEGIN
- e.CheckMenu;
- IF version # e.cur THEN
- i := e.IndexOf(version); j := e.IndexOf(e.cur);
- IF i >= 0 THEN
- t := Texts.ElemBase(e); beg := Texts.ElemPos(e) + 1; end := e.TwinPos();
- IF end >= 0 THEN
- Texts.Delete(t, beg, end);
- Texts.Insert(t, beg, e.buf[i]);
- IF j >= 0 THEN Texts.Recall(e.buf[j]) END;
- COPY(version, e.cur)
- END
- ELSE Out.String("-- no version "); Out.String(version); Out.F(" at pos #$", Texts.ElemPos(e))
- END
- END SwitchTo;
- Syntax10.Scn.Fnt
- PictElems
- Alloc
- VAR line: ARRAY 10 OF SET;
- BEGIN
- line[1] := {4};
- line[2] := {3};
- line[3] := {2};
- line[4] := {1};
- line[5] := {0};
- line[6] := {1};
- line[7] := {2};
- line[8] := {3};
- line[9] := {4};
- begIcon := Display.NewPattern(line, 6, 9);
- line[1] := {1};
- line[2] := {2};
- line[3] := {3};
- line[4] := {4};
- line[5] := {5};
- line[6] := {4};
- line[7] := {3};
- line[8] := {2};
- line[9] := {1};
- endIcon := Display.NewPattern(line, 6, 9);
- END InitIcons;
- Syntax10.Scn.Fnt
- END NoNotify;
- Syntax10.Scn.Fnt
- VAR r: Texts.Reader; pos: LONGINT; e: Beg;
- BEGIN
- Texts.OpenReader(r, t, 0);
- LOOP
- Texts.ReadElem(r);
- IF r.eot THEN EXIT END;
- IF r.elem IS Beg THEN
- pos := Texts.Pos(r) + 1; e := r.elem(Beg); e.SwitchTo(version); Texts.OpenReader(r, t, pos)
- END
- END SwitchAll;
- Syntax10.Scn.Fnt
- Syntax10b.Scn.Fnt
- VAR beg, end, delta: LONGINT;
- BEGIN delta := 200;
- LOOP beg := f.org; end := TextFrames.Pos(f, f.X + f.W, f.Y);
- IF (beg <= pos) & (pos < end) OR (delta = 0) THEN EXIT END;
- TextFrames.Show(f, pos - delta); delta := delta DIV 2
- END;
- TextFrames.SetCaret(f, pos)
- END ShowPos;
- Syntax10m.Scn.Fnt
- Syntax10.Scn.Fnt
- Syntax10m.Scn.Fnt
- Syntax10i.Scn.Fnt
- VAR e1: Beg; i: INTEGER; str: ARRAY 32 OF CHAR; s: Texts.Scanner;
- BEGIN
- WITH e: Beg DO
- WITH m: TextFrames.DisplayMsg DO
- IF ~m.prepare THEN
- Display.CopyPattern(Display.white, begIcon, m.X0, m.Y0+3, Display.paint)
- END
- | m: TextPrinter.PrintMsg DO
- IF m.prepare THEN e.W := 1 ELSE e.W := 7*pixel END
- | m: Texts.CopyMsg DO
- IF m.e = NIL THEN NEW(e1); m.e := e1 ELSE e1 := m.e(Beg) END;
- COPY(e.cur, e1.cur); i := 0;
- WHILE (i < maxVersions) & (e.vers[i] # "") DO
- COPY(e.vers[i], e1.vers[i]);
- NEW(e1.buf[i]); Texts.OpenBuf(e1.buf[i]); Texts.Copy(e.buf[i], e1.buf[i]);
- INC(i)
- END;
- PopupElems.Handle(e, m)
- | m: Texts.IdentifyMsg DO
- m.mod := "VersionElems"; m.proc := "AllocBeg"
- | m: Texts.FileMsg DO
- PopupElems.Handle(e, m);
- IF m.id = Texts.load THEN
- Files.ReadString(m.r, e.cur);
- Files.ReadString(m.r, str); i := 0;
- WHILE str # "" DO
- COPY(str, e.vers[i]);
- Texts.Load(m.r, scratch); Texts.Delete(scratch, 0, scratch.len);
- NEW(e.buf[i]); Texts.Recall(e.buf[i]);
- INC(i); Files.ReadString(m.r, str)
- END
- ELSE (*Texts.store*)
- Files.WriteString(m.r, e.cur); i := 0;
- WHILE (i < maxVersions) & (e.vers[i] # "") DO
- Files.WriteString(m.r, e.vers[i]);
- Texts.Append(scratch, e.buf[i]); Texts.Store(m.r, scratch);
- Texts.Delete(scratch, 0, scratch.len); Texts.Recall(e.buf[i]);
- INC(i)
- END;
- Files.WriteString(m.r, "")
- END
- | m: PopupElems.ExecMsg DO
- Texts.OpenScanner(s, e.menu, m.pos); Texts.Scan(s);
- IF s.class = Texts.Name THEN SwitchAll(Texts.ElemBase(e), s.s) END
- ELSE PopupElems.Handle(e, m)
- END
- END HandleBeg;
- Syntax10.Scn.Fnt
- Syntax10m.Scn.Fnt
- VAR e1: End; keys: SET; x, y: INTEGER;
- BEGIN
- WITH e: End DO
- WITH m: TextFrames.DisplayMsg DO
- IF ~m.prepare THEN
- Display.CopyPattern(Display.white, endIcon, m.X0, m.Y0+3, Display.paint)
- END
- | m: TextPrinter.PrintMsg DO
- IF m.prepare THEN e.W := 1 ELSE e.W := 7*pixel END
- | m: Texts.CopyMsg DO
- IF m.e = NIL THEN NEW(e1); m.e := e1 ELSE e1 := m.e(End) END;
- Texts.CopyElem(e, e1)
- | m: Texts.IdentifyMsg DO
- m.mod := "VersionElems"; m.proc := "AllocEnd"
- | m: TextFrames.TrackMsg DO
- IF m.keys = {MM} THEN
- REPEAT
- Input.Mouse(keys, x, y); Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
- UNTIL keys = {}
- END
- ELSE
- END
- END HandleEnd;
- Syntax10.Scn.Fnt
- VAR e: Beg;
- BEGIN
- NEW(e); e.handle := HandleBeg; Texts.new := e
- END AllocBeg;
- Syntax10.Scn.Fnt
- VAR e: End;
- BEGIN
- NEW(e); e.handle := HandleEnd; Texts.new := e
- END AllocEnd;
- Syntax10.Scn.Fnt
- VAR a: Beg; b: End; t: Texts.Text; beg, end, time: LONGINT; s: Texts.Scanner;
- BEGIN
- Oberon.GetSelection(t, beg, end, time);
- IF time >= 0 THEN
- Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(s);
- IF s.class = Texts.Name THEN
- NEW(a);
- a.W := 7*pixel; a.H := 11*pixel; a.handle := HandleBeg; COPY(s.s, a.cur);
- a.menu := TextFrames.Text("");
- Texts.WriteString(w, s.s); Texts.Append(a.menu, w.buf); PopupElems.MeasureMenu(a);
- Texts.WriteElem(w, a); Texts.Insert(t, beg, w.buf);
- NEW(b);
- b.W := 7*pixel; b.H := 11*pixel; b.handle := HandleEnd;
- Texts.WriteElem(w, b); Texts.Insert(t, end+1, w.buf)
- ELSE Out.String("-- version name must be an Oberon name$")
- END
- ELSE Out.String("-- no selection$")
- END Insert;
- Syntax10.Scn.Fnt
- VAR version: ARRAY 32 OF CHAR; v: Viewers.Viewer; t: Texts.Text;
- BEGIN
- In.Open; In.Name(version);
- IF In.Done THEN
- v := Oberon.MarkedViewer();
- IF (v # NIL) & (v.dsc.next # NIL) & (v.dsc.next IS TextFrames.Frame) THEN
- t := v.dsc.next(TextFrames.Frame).text;
- SwitchAll(t, version)
- END
- ELSE Out.String("-- version name must be an Oberon name$")
- END SetVersion;
- Syntax10.Scn.Fnt
- VAR v: Viewers.Viewer; f: TextFrames.Frame; r: Texts.Reader; pos: LONGINT;
- BEGIN
- v := Oberon.FocusViewer;
- IF (v # NIL) & (v.dsc.next # NIL) & (v.dsc.next IS TextFrames.Frame) THEN
- f := v.dsc.next(TextFrames.Frame);
- IF f.hasCar THEN pos := f.carloc.pos ELSE pos := 0 END;
- Texts.OpenReader(r, f.text, pos);
- REPEAT Texts.ReadElem(r) UNTIL r.eot OR (r.elem IS Beg);
- IF ~r.eot THEN ShowPos(f, Texts.Pos(r)) ELSE TextFrames.RemoveCaret(f) END
- END Find;
- MODULE VersionElems;
- (* HM 14 Sep 95 /
- IMPORT Display, Viewers, Files, Input, Texts, TextFrames, TextPrinter, Oberon, PopupElems, In, Out;
- CONST
- maxVersions = 8;
- pixel = LONG(10000);
- ML = 2; MM = 1; MR = 0;
- Beg* = POINTER TO BegDesc;
- BegDesc* = RECORD (PopupElems.ElemDesc)
- cur: ARRAY 32 OF CHAR; (*current version*)
- vers: ARRAY maxVersions, 32 OF CHAR; (*version names*)
- buf: ARRAY maxVersions OF Texts.Buffer (*version texts*)
- END;
- End* = POINTER TO EndDesc;
- EndDesc* = RECORD (Texts.ElemDesc) END;
- begIcon, endIcon: Display.Pattern; (* x = 0, y = 3, w = 6, h = 9 *)
- scratch: Texts.Text;
- w: Texts.Writer;
- PROCEDURE (e: Beg) IndexOf (version: ARRAY OF CHAR): INTEGER;
- PROCEDURE (e: Beg) CheckMenu;
- PROCEDURE (e: Beg) TwinPos (): LONGINT;
- PROCEDURE (e: Beg) SwitchTo (version: ARRAY OF CHAR);
- PROCEDURE InitIcons;
- PROCEDURE NoNotify (t: Texts.Text; op: INTEGER; beg, end: LONGINT);
- PROCEDURE SwitchAll (t: Texts.Text; version: ARRAY OF CHAR);
- PROCEDURE ShowPos (f: TextFrames.Frame; pos: LONGINT);
- PROCEDURE HandleBeg* (e: Texts.Elem; VAR m: Texts.ElemMsg);
- PROCEDURE HandleEnd* (e: Texts.Elem; VAR m: Texts.ElemMsg);
- PROCEDURE AllocBeg*;
- PROCEDURE AllocEnd*;
- PROCEDURE Insert*;
- PROCEDURE SetVersion*;
- PROCEDURE Find*;
- BEGIN
- InitIcons;
- Texts.OpenWriter(w);
- NEW(scratch); Texts.Open(scratch, ""); scratch.notify := NoNotify
- END VersionElems.
-